import { Alert } from '@aws-amplify/ui-react';
import { Example } from '@/components/Example';
import { CustomizationCdn } from './CustomizationCdn';

## Custom CDN

FaceLivenessDetector allows overriding the default hosted CDN and providing your own. The CDN files are used by the TensorFlow library to load in files at runtime. You can host your own CDN by following the instructions below.

<Alert role="none" variation="info">
Learn more about the differences between the three different `.wasm`  files in [this TensorFlow blog post](https://blog.tensorflow.org/2020/09/supercharging-tensorflowjs-webassembly.html).
</Alert>

1. Download the TFJS wasm and blazeface files for the corresponding version of `@aws-amplify/ui-react-liveness`.
    - Download wasm files for tfjs here:
        - \<= v2.x
            - https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-backend-wasm@3.11.0/dist/tfjs-backend-wasm.wasm
            - https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-backend-wasm@3.11.0/dist/tfjs-backend-wasm-simd.wasm
            - https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-backend-wasm@3.11.0/dist/tfjs-backend-wasm-threaded-simd.wasm
        - v3.x
            - https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-backend-wasm@4.11.0/dist/tfjs-backend-wasm.wasm
            - https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-backend-wasm@4.11.0/dist/tfjs-backend-wasm-simd.wasm
            - https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-backend-wasm@4.11.0/dist/tfjs-backend-wasm-threaded-simd.wasm
    - Download and unzip the tar file. It should contain a `model.json` file and a `group1-shard1of1.bin` file.
        - \<= v2.x - https://tfhub.dev/tensorflow/tfjs-model/blazeface/1/default/1
        - v3.x - https://tfhub.dev/mediapipe/tfjs-model/face_detection/short/1
1. Host all files alongside your JS files on your own server
1. Update FaceLivenessDetector code:

```tsx file=./CustomizationCdn.tsx
```

<Alert role="none" variation="warning">
`binaryPath` must be a path to a folder with `.wasm` files. `faceModelUrl` must point to the `model.json` file and will also expect the `group1-shard1of1.bin` file to be colocated in the same path.
</Alert>
